package com.csii.activiti.server.core.entity;

import com.csii.activiti.server.abstraction.entity.ActUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
@ApiModel("配置项")
public class ActFlowConfigurationItem {
    @ApiModelProperty("表单内容设置")
    private List<ActFlowFormContentSetting> formContentSetting;
    @ApiModelProperty("动作设置")
    private List<ActFlowActionSetting> actionSetting;
    @ApiModelProperty("审批机制(会签和或签)")
    private String approvalMechanism;
    @ApiModelProperty("相邻节点合并")
    private boolean mergeAdjacentNodes;
    @ApiModelProperty("发起人相同过滤")
    private boolean originatorSameFilter;
    @ApiModelProperty("是否需要数字签名")
    private boolean digitalSignature;
    @ApiModelProperty("审批人为空时(自动通过,自动拒绝,指定备用审批人)")
    private String approvalIsEmpty;
    @ApiModelProperty("指定节点备用审批人")
    private List<ActUser> standbyApprover;
    @ApiModelProperty("流程催办配置")
    private ActFlowUrgingConfiguration flowUrgingConfiguration;
    @ApiModelProperty("流程自动审批")
    private ActFlowAutoApprovalConfiguration flowAutoApprovalConfiguration;


    public void coverageIsNullCurrent(ActFlowConfigurationItem coverageConfigurationItem){
        if (formContentSetting == null && coverageConfigurationItem.getFormContentSetting() != null){
            formContentSetting = coverageConfigurationItem.getFormContentSetting();
        }
        if (actionSetting == null && coverageConfigurationItem.getActionSetting() != null){
            actionSetting = coverageConfigurationItem.getActionSetting();
        }
        if (approvalMechanism == null && coverageConfigurationItem.getApprovalMechanism() != null){
            approvalMechanism = coverageConfigurationItem.getApprovalMechanism();
        }
        if (!mergeAdjacentNodes && coverageConfigurationItem.isMergeAdjacentNodes()){
            mergeAdjacentNodes = true;
        }
        if (!originatorSameFilter && coverageConfigurationItem.isOriginatorSameFilter()){
            originatorSameFilter = true;
        }
        if (!digitalSignature && coverageConfigurationItem.isDigitalSignature()){
            digitalSignature = true;
        }
        if (approvalIsEmpty == null && coverageConfigurationItem.getApprovalIsEmpty() != null){
            approvalIsEmpty = coverageConfigurationItem.getApprovalIsEmpty();
        }
        if (standbyApprover == null && coverageConfigurationItem.getStandbyApprover() != null){
            standbyApprover = coverageConfigurationItem.getStandbyApprover();
        }
        if ((flowUrgingConfiguration == null || !flowUrgingConfiguration.isFlag()) && coverageConfigurationItem.getFlowUrgingConfiguration() != null){
            ActFlowUrgingConfiguration item = coverageConfigurationItem.getFlowUrgingConfiguration();
            this.flowUrgingConfiguration = new ActFlowUrgingConfiguration(null,item.getRemindType(),item.getDelayHour(),false);
        }
        if ((flowAutoApprovalConfiguration == null || !flowAutoApprovalConfiguration.isFlag()) && coverageConfigurationItem.getFlowAutoApprovalConfiguration() != null){
            ActFlowAutoApprovalConfiguration item = coverageConfigurationItem.getFlowAutoApprovalConfiguration();
            this.flowAutoApprovalConfiguration = new ActFlowAutoApprovalConfiguration(null,item.getApprovalType(),item.getDelayHour(),false);
        }
    }

}
